By the end of this assignment, you should be able will:
Work through the following assignment, making sure to follow all of the directions and answer all of the questions.
There are 100 points possible on this assignment. Point values for each part are included in the section headers and question prompts.
This assignment is due roughly two weeks from now at 11:59 pm on Friday, February 3rd. It should be uploaded into the "Homework Assignments" submission folder for Homework #1 on D2L. Submission instructions can be found at the end of the notebook.
"As a Spartan, I shall work to uphold the highest moral principles. I will strive to be honest in my work and in my interactions with others. I will also take delight in the knowledge that honor is more important than grades. After I graduate from Michigan State University, I'll continue to uphold these ideals and work to develop my personal integrity in whatever I do.
We want to make sure that everyone knows how to access the resources available to you. One of the best resources you have at your disposal is office hours.
(At minimum) Go to one office hour session (it doesn’t matter which one you go to). Come with one question that you would like to talk about. It can be big or small. Ask your question. All of the instructors for CMSE 202 (section leads, TAs, and LAs) will be adding to a running list of folks that we see during office hours; as long as your name appears on the list, you’ll get credit for this part of Homework 1.
NOTE: The day when the homework is due (Friday, February 3rd) will be the busiest time for folks to go to office hours. You are STRONGLY encouraged to go to office hours before Friday to get credit for this part of this assignment. (You should still feel free to go to office hours on Friday for help, though!)
You can find the office hours calendar on the course website.
✅ Question 0.1 (8 points)****
Type below the question you asked.
Were you born on a Friday?
You have spent some time in class learning about how/why we use git in CMSE 202 and beyond, and you will be expected to use it throughout the semester.
You are working collaboratively with a team on a research project that includes developing code as well as writing a paper to communicate your results, and you need to ensure that all work is managed and tracked with git. Since you are learning about git in your class, your groupmates have asked you to propose a software development workflow for this project. Here, workflow is defined as the process by which the project is managed and developed.
Your workflow must (at least) handle the following:
In the cell below, write down the guidelines for your proposed workflow, making sure to account for all of the items mentioned above.
In the cell(s) below, demonstrate that your workflow works by performing (or answering) the following tests:
# put any code here (feel free to add additional cells)
git clone https://github.com/aryandhr/CMSE202-s23-turnin
touch paper_draft.txt
vi paper_draft.txt
# inserted proposed workflow into text file.
git add paper_draft.txt
git commit -m "Initial commit - proposed workflow"
git push origin main
File "<ipython-input-1-91fc3c169e87>", line 2 git clone https://github.com/aryandhr/CMSE202-s23-turnin ^ SyntaxError: invalid syntax
Answer the following questions in the cell below about your workflow:
You should commit early and often, but at least do it after you complete each homework problem.
Make sure to use meaningful commit messages that indicate the changes you have made!
Bugs are a part of life in writing code. They do not mean you are not making progress at coding. However, you can employ various debugging strategies to help you work through bugs efficiently and confidently.
In the cell below, explain debugging to a CMSE 201 student, and describe the process you would recommend they use to debug their code. You must include how you would solve the various types of bugs you can encounter while coding. Remember all of the resources you can use in CMSE 201/202 (particularly Google or other search engines!).
My first step when debugging is thinking about what I want my code to do, and then think about what it is currently doing. Using the dubgger in VSCode is a great tool to see what values your variables are taking, how they are getting updated as your code runs, what exactly your functions are outputting and much more. One debugging tool I have recently discovered is pythontutor which a website where you can run your Python code and it takes you step by step through the code and tells you what each line is doing. It is always okay to Google your errors, ask for help on Slack, go to helprooms. However, it is not okay to plagiarize code and let someone else fix your code. You must understand why your code isn't working and then fix the problem.
Run the code in the cell below. There are (at least) 2 bugs to find and fix! Complete the following questions:
import numpy as np # import modules at the top to avoid issues later when debugging
# function that returns a random number of squirrels spotted between 0 and the limit
def squirrel_spotting_simulation(limit=15):
random_squirrels = np.random.randint(limit)
return random_squirrels
# initialize number of squirrels
squirrel_count = 0
# initialize number of time steps
t = 0
# loop until the observer reaches a maximum of 100 squirrels spotted
while squirrel_count <= 100:
# use our function to generate a random number of squirrels spotted
increment = squirrel_spotting_simulation(15)
# increment the number of time steps by 1
t+=1
# add the number of random squirrels this time step to the total number
squirrel_count+=increment
# print the total number of timesteps it took
print(t)
14
Yes, the debugging process worked. It was easier to visualize once I run it locally in VSCode.
Run the code in the cell below, then answer the following questions: set_xlabel vs. label
# code to plot two randomly generated data sets (sin and cos) on one plot
import matplotlib.pyplot as plt
import numpy as np
# generate some x data: sixty data points from 0 to 4π
x_sin = np.linspace(0,4*np.pi,60)
# generate some y data: 1.5 * sin(1.2x + 0.5)
# we add the np.random.normal(0.25,.25,60) at the end to add some randomness to the data
y_sin = 1.5 * np.sin(1.2 * x_sin + 0.5) + np.random.normal(.25,.25,60)
y_cos = 1.5 * np.cos(1.2 * x_sin + 0.5) + np.random.normal(.25,.25,60)
# plot our data
plt.scatter(x_sin, y_sin, label = "sin data")
plt.xlabel('x')
plt.ylabel('y')
plt.scatter(x_sin, y_cos, label = "cos data")
plt.legend()
<matplotlib.legend.Legend at 0x7f5c0b9cb5b0>
The set_xlabel method, as follows from its name, sets the label for the x axis. In this example, we have it set as "x". The label attribute on the other hand, "labels" our graph with the string we provide it with. Here, we have two plots and we use the label attribute in both, appropriately, to name each set's data. It is important to include the plt.legend() statement to actually see these labels.
You should commit early and often, but at least do it after you complete each homework problem.
In Part 1, you developed a workflow for the project your team is working on. One of your team members found this package that will help with some of the visualizations, however you discover that you don't currently have this package installed.
A quick Google search tells you that the plotly Python library is an interactive, open-source plotting library that supports over 40 unique chart types covering a wide range of statistical, financial, geographic, scientific, and 3-dimensional use-cases. Sounds great, let's figure this out!
You remember from class that you can install packages using the command line. Using your terminal, install the plotly package, then answer the following questions.
In the cell below, write down the command you used to install the package.
pip install plotly==5.13.0 # accessed from plotly documentation @ https://plotly.com/python/getting-started/
Particularly if you are using JupyterHub, you may get a message similar to this one in your terminal:

This means that the package has already been installed. If that is the case, you still need to provide the command you would use to install the package above, and then proceed to the rest of this problem.
Now that you've installed Plotly, its time to explore the package! What can this package do? The best place to find this information is in the documentation.
Answer the following questions:
Finally, it's time to use the newly installed package! Pick a dataset from the data package that is a part of Plotly.
Create a graph using one of these datasets. You can use the documentation for inspiration, but try to change the variables around so you get to really experience the package! Make sure to include titles and axis labels!
import plotly.express as px
df = px.data.stocks()
fig = px.line(df, y=df['MSFT'], x=df["date"], title='Microsoft Stock closing prices from 2018/2019')
fig.show()
✅ Have you put your name and GitHub username at the top of your notebook?
Yes
✅ Have you added the TA and Instructor to your GitHub repository?
Yes
✅ Merge your homework_01 branch into the main branch and checkout the main branch
# Put the command you used to merge your branch here
git merge homework_01 main
✅ Push your repository to GitHub.
# Put the command you used to push to GitHub here
git push origin main
NOTE: The grader is able to see your commit messages, branches and whether you pushed the repo at this stage.
Submit this assignment by uploading it to the course Desire2Learn web page. Go to the "Homework Assignments" folder, find the dropbox link for Homework #1, and upload it there.
© Copyright 2023, Department of Computational Mathematics, Science and Engineering at Michigan State University